package com.call.project.frame;

import java.awt.*;
import java.awt.event.ActionListener;

/**
 Created by IntelliJ IDEA.
 User: wk
 Date: 2017-03-20 下午12:59
 */
public class TrayManager {
    private MenuItem exit;
//    private MenuItem run;
    private MenuItem setting;
//    private MenuItem register;
    private MenuItem about;

    public void init(ActionListener actionListener) {
        MyTrayIcon myTrayIcon = new MyTrayIcon();
        myTrayIcon.setImageAutoSize(true);
        myTrayIcon.setToolTip("右键点击");
        //创建弹出菜单
        PopupMenu menu = new PopupMenu();
        //添加一个用于退出的按钮
        exit = new MenuItem("退出");
        exit.setActionCommand(CommandEnum.EXIT.command);
        exit.addActionListener(actionListener);
//        run = new MenuItem("关闭服务");
//        run.setActionCommand(CommandEnum.STOPRUN.command);
//        run.addActionListener(actionListener);

        setting = new MenuItem("设置");
        setting.setActionCommand(CommandEnum.SETTING.command);
        setting.addActionListener(actionListener);
//        register = new MenuItem("注册");
//        register.setActionCommand(CommandEnum.REGISTER.command);
//        register.addActionListener(actionListener);

        about = new MenuItem("关于软件");
        about.setActionCommand(CommandEnum.ABOUT.command);
        about.addActionListener(actionListener);
//        menu.add(run);
//        menu.add(register);
        menu.add(setting);
        menu.add(about);
        menu.add(exit);
        myTrayIcon.setPopupMenu(menu);
        SystemTray tray = SystemTray.getSystemTray();//获取系统托盘
        try {
            tray.add(myTrayIcon);
        } catch (AWTException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } //将托盘图表添加到系统托盘
    }

    public enum CommandEnum {
                             EXIT("exit"), RUN("run"), STOPRUN("stopRun"), REGISTER("register"), SETTING("setting"), ABOUT("about");
        private CommandEnum(String command) {
            this.command = command;
        }

        private String command;

        public String getCommand() {
            return command;
        }

    }
}
